package ferp.core.ai.strategy.simple;

import ferp.core.ai.strategy.Passing;
import ferp.core.card.Card;
import ferp.core.player.AI;

/**
 * User: igorgok
 * Date: 5/30/11 5:18 PM
 */
public class SimplePassing extends Passing
{
  @Override
  public Card move(AI ai)
  {
/*
    Hand candidates = Game.ferp().current.player.hand.getMoveCandidates();
    Hand tricks = new Hand();

    for (Card.Suit s : Card.Suit.rising)
    {
      Card.Set mine = new Card.Set(candidates.cards(s));

      if (mine.size() > 0)
      {
        Card.Set remaining = new Card.Set(mine, Game.ferp().trash.cards(s));

        // cards still in the game
        remaining.invert();

        if (remaining.size() > 0)
        {
          // get talon card which is now on the table
          Card card = Game.ferp().trick.get();
          // remove talon card if any
          if (card != null && card.suit() == s)
            remaining.remove(card.rank());

          while (mine.size() > 0 && remaining.size() > 0)
          {
            if (mine.lowest().ordinal() > remaining.lowest().ordinal())
            {
              tricks.add(s, mine.highest());
              mine.remove(mine.highest());
            }
            else
              mine.remove(mine.lowest());

            remaining.remove(remaining.lowest());
          }
        }
      }
    }

    // try to win the trick (take mine)
    for (Card.Suit s : Card.Suit.rising)
      if (tricks.cards(s).size() > 0)
        return Game.ferp().deck().card(s, tricks.cards(s).highest());

    Card highest = Game.ferp().trick.highest(Game.ferp().trump());

    if (highest == null)
    {
      // first hand
      for (Card.Suit s : Card.Suit.rising)
        if (candidates.cards(s).size() > 0)
          return Game.ferp().deck().card(s, candidates.cards(s).highest());

      assert false : "no cards on first hand??";
    }
    else
    {
      if (candidates.cards(highest.suit()).size() > 0)
      {
        Card.Rank lower = candidates.cards(highest.suit()).lower(highest.rank());
        if (lower != null)
          return Game.ferp().deck().card(highest.suit(), lower);
      }

      for (Card.Suit s : Card.Suit.rising)
        if (candidates.cards(s).size() > 0)
          return Game.ferp().deck().card(s, candidates.cards(s).highest());

      assert false : "no cards on " + (Game.ferp().hand + 1) + " hand??";
    }
*/

    // should never get here
    return null;
  }
}
